<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('借阅人') }}</td>
        <td>{{ form.borrowerName }}</td>
        <td class="tit">{{ $t('申请时间') }}</td>
        <td>{{ parseTime(form.applicationTime) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('截止时间') }}</td>
        <td>{{ parseTime(form.deadlineTime) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('借阅说明') }}</td>
        <td colspan="3">{{ form.borrowingInstructions }}</td>
      </tr>
    </table>

    <div v-if="form.fileBorrowingList && form.fileBorrowingList.length > 0">
      <div class="area-header">
        <span class="area-header-title">{{ $t('文件列表') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('附件类型') }}</th>
          <th>{{ $t('业务名称') }}</th>
          <th>{{ $t('文件名称') }}</th>
          <th>{{ $t('状态') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.fileBorrowingList" :key="ind">
            <td>
              {{ v.type }}
            </td>
            <td>{{ v.businessName }}</td>
            <td>{{ v.name }}</td>
            <td>
              <span v-show="v.status === '借阅中'">
                {{ $t(v.status) }}
              </span>
              <span v-show="v.status === '已过期'">
                {{ $t(v.status) }}
              </span>
              <span v-show="v.status !== '借阅中' && v.status !== '已过期'">
                {{ $t(v.status) }}
              </span>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>
<script>
import {
  getOaFileLending
} from '@/api/oa/oaFileLending/oaFileLending'
export default {
  components: {},
  data() {
    return {
      btnHide: false,
      otherBtnHide: false,
      form: {},
      buttonShow: true
    }
  },
  created() {
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getOaFileLending(data.id).then((response) => {
          this.form = response.data
          this.calculateReviewStatus(response.data.fileBorrowingList)
        })
      }
    },
    // 计算审阅状态
    calculateReviewStatus(rows) {
      rows.forEach((item) => {
        console.log(item)
        if (new Date(this.form.deadlineTime).getTime() > new Date().getTime()) {
          if (this.form.actStatus === 'W') {
            item.status = '借阅中'
          } else {
            item.status = '待审核'
          }
        } else {
          item.status = '已过期'
        }
      })
    }
  }
}
</script>
